<template>
	<view class="content reg-page">
		<view class="input-group">
			<view class="input-column border-bottom-1px">
				<text class="title">学校名称</text>
				<view class="input-item"><input class="padding-10" placeholder="请输入学校名称" v-model="expect.educationSchoolName" /></view>
			</view>

			<view class="input-column border-bottom-1px">
				<text class="title">学历</text>				
				<view class="picker">
					<picker @change="bindPickerChange" :value="salaryIndex" :range-key="'dictValue'" :range="array">
						<input class="padding-10" disabled placeholder="请选择学历" :value="expect.educationName" />
					</picker>					
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">专业</text>
				<view class="input-item"><input class="padding-10" placeholder="请输入专业名称" v-model="expect.educationSubjectName" /></view>
			</view>

			<view class="input-column border-bottom-1px">
				<text class="title">时间段</text>
				<view class="row space-between-algin">
					<picker mode="date" :value="expect.resumeBeginWorkTime" :start="startDate" :end="endDate" @change="bindDate1Change">
						<input class="padding-10" disabled placeholder="开始时间" :value="expect.educationTimeBegin.slice(0,10)" />
					</picker>
					至
					<picker mode="date" :value="expect.educationTimeEnd" :start="startDate" :end="endDate" @change="bindDate2Change">
						<input class="padding-10" disabled style="text-align: center;" placeholder="结束时间" :value="expect.educationTimeEnd.slice(0,10)" />
					</picker>
				</view>
			</view>
			<view class="input-column border-bottom-1px" @click="toWorkContent(expect.educationWrok)">
				<text class="title">在校经历</text>
				<view class="space-between-algin row padding-height-20">
					<input class="padding-10" v-if="expect.educationWrok == ''" disabled="true" placeholder="(选填)请输入"/>
					<view class="two-ellipsis" v-else>{{expect.educationWrok}}</view>
					<text class="yzb yzb-next"></text>
				</view>
			</view>
		</view>
		<view class="btn-row row">
			<button v-if="expEduId" type="warn" class="btn-delete" @tap="remove(expEduId)">删除</button>
			<button type="primary" class="btn-save" :class="expEduId ? 'width-55' : 'width-90'" @tap="register">保存</button>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import { formatDate, calCurrentYear } from '@/common/date';
export default {
	components: {},
	computed: {
		...mapState(['openId', 'customerInfo']),
		startDate() {
			return this.getDate('start');
		},
		endDate() {
			return this.getDate('end');
		}
	},

	data() {
		const currentDate = this.getDate({format: true});
		const currentTime = this.getTime({format: true});//当前时间
		return {
			bindTimee: currentTime,
			expEduId:'',
			resumeId:'',
			array: [],
			salaryIndex: 0,
			expect:{				
				educationTimeBegin:'',
				educationTimeEnd:'',
				educationWrok:'',
			}
			
		};
	},
	onLoad(query) {	
		this.expEduId = query.expEduId
		this.resumeId = query.resumeId
		if(this.expEduId){
			this.getDetail()
		}
	},
	onShow() {
		console.log(this.expect)
	},
	mounted() {
		let that = this	
		this.getEducational()		
	},
	methods: {	
		//详情		
		async getDetail(){
			var that = this
			let res= await this.$apis.getDatileEduInfo(this.expEduId);
			if(res.msg =="操作成功"){				
				that.expect = res.data				
			}
		},
		//获取学历
		async getEducational(){
			let data = await this.$apis.getEducational();
			if(data){
				this.array = data.data
			}
		},
		//选择学历
		bindPickerChange: function(e) {
			this.salaryIndex = e.target.value;
			this.expect.educationName = this.array[this.salaryIndex].dictValue;
		},
		//时间段
		bindDate1Change: function(e) {
			this.expect.educationTimeBegin = e.target.value;
		},
		bindDate2Change: function(e) {
			this.expect.educationTimeEnd = e.target.value;
		},

		toIndustry() {
			this.$mRouter.push({
				route: this.$mRoutesConfig.industry,
				query: {
					id: 1
				}
			});
		},

		toPost() {
			this.$mRouter.push({
				route: this.$mRoutesConfig.post,
				query: {
					id: 1
				}
			});
		},
		
		toWorkContent(content) {
			console.log(content)
			this.$mRouter.push({
				route: this.$mRoutesConfig.editProContent,
				query: {
					type: 3,
					content:content
				}
			});
		},

		// 点击注册按钮
		async register() {
			if (!this.expect.educationSchoolName) {
				uni.showToast({
					icon: 'none',
					title: '请输入学校名称'
				});
				return;
			}			
			if (!this.expect.educationName) {
				uni.showToast({
					icon: 'none',
					title: '请选择学历'
				});
				return;
			}
			if (!this.expect.educationSubjectName) {
				uni.showToast({
					icon: 'none',
					title: '请输入专业名称'
				});
				return;
			}
			if (!this.expect.educationTimeBegin) {
				uni.showToast({
					icon: 'none',
					title: '请选择开始时间'
				});
				return;
			}
			if (!this.expect.educationTimeEnd) {
				uni.showToast({
					icon: 'none',
					title: '请选择结束时间'
				});
				return;
			}
			this.expect.educationTimeBegin = this.expect.educationTimeBegin+' '+ this.bindTimee+":00"
			this.expect.educationTimeEnd = this.expect.educationTimeEnd+' '+ this.bindTimee+":00"
			if(!this.expEduId){
				//新增
				this.expect.resumeId = this.resumeId
				let res=await this.$apis.addEduInfo(this.expect);
				if(res){
					uni.navigateBack({
						delta:1
					})
				}				
			}else{
				//修改
				let res = await this.$apis.eidtEduInfo(this.expect);
				if(res){
					uni.navigateBack({
						delta:1
					})
				}
			}
		},
		async remove(expEduId) {
			let res = await this.$apis.deltelEduInfo(expEduId);
			if (res) {
				uni.navigateBack({
					delta: 1
				});
			}
		},
		getDate(type) {
			const date = new Date();
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();
		
			if (type === 'start') {
				year = year - 60;
			} else if (type === 'end') {
				year = year + 2;
			}
			month = month > 9 ? month : '0' + month;
			day = day > 9 ? day : '0' + day;
			return `${year}-${month}-${day}`;
		},
		formatDates(time) {
			if (time == null || time === '') {
				return null;
			}
			let date = new Date(time);
			return formatDate(date, 'yyyy-MM-dd');
		},
		// 获取当前时间
		getTime(type) {
			const date = new Date();
			let hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
			let minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
			return `${hour}:${minute}`;
		},
	}
};
</script>

<style lang="scss" scoped>
input {
	width: 90%;
}
.input-group {
	border-radius: 10upx;
	margin-top: 10upx;
	overflow: hidden;
	margin-bottom: 120upx;
}

.input-row {
	display: flex;
	flex-direction: row;
	position: relative;
	background: #fff;
	justify-content: space-between;
	align-items: center;
	padding: 15upx 10upx;
}

.input-row .title {
	width: 25%;
	padding: 20upx 0;
	padding-left: 20upx;
	line-height: 50upx;
}

.border-bottom-1px {
	position: relative;

	&::after {
		position: absolute;
		z-index: 1;
		right: 0;
		bottom: 0;
		left: 20upx;
		height: 1upx;
		content: '';
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		background-color: #e2e2e2;
	}
}

.header {
	display: flex;
	flex-direction: column;
	.tip {
		font-size: $uni-font-size-sm;
		color: $font-color-666;
		margin-left: 20upx;
	}
}

.head-img {
	margin-right: 15upx;
	image {
		width: 160upx;
		height: 160upx;
		border-radius: 50%;
	}
}

radio-group {
	margin-right: 10upx;
}

.radio {
	margin-left: 20upx;
}

.input-column {
	display: flex;
	flex-direction: column;
	background-color: $bgcolor_white;
	padding: 30upx 20upx 10upx 20upx;

	.title {
		margin-left: 10upx;
	}

	.input-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.picker {
		padding: 30upx 0;
		margin-left: 10upx;
		position: relative;
		picker {
			font-size: $uni-font-size-lg;
			width: 100%;
			position: absolute;
		}
	}
	.yzb-next {
		float: right;
		color: $font-color-999;
	}
}

.content {
	background: $bgcolor_white;
}

.btn-row {
	position: fixed;
	bottom: 20upx;
	width: 100%;
	box-sizing: border-box;
	background-color: #FFFFFF;
	padding-bottom: constant(safe-area-inset-bottom);
	padding-bottom: env(safe-area-inset-bottom);
	box-sizing: content-box;	
	.btn-delete{
		background-color:#ccc;
		height: 90upx;
		line-height: 90upx;
		font-size: 34rpx;
		color: #333;
		width: 50%;
	}
	
	.btn-save{
		background-color: #84C0F4;
		height: 90upx;
		line-height: 90upx;
		font-size: 34rpx;
	}
	.width-55{
		width: 50%;
	}
	
	.width-90{
		width: 90%;
		display: block;
		margin: 0 auto;
	}
}
</style>
